import java.util.Arrays;

public class Test {
    //创建数组
    public static void main(String[] args) {
        int[] array = {1,2,3,4,5};
        array[0] = 99;
        //或者换种形式创建数组
        int[] array2 = new int[] {1,2,3,4};
        int[] array3 = new int[10];
        System.out.println(array[0]);
        System.out.println(array[1]);
        //求数组的长度
        System.out.println(array.length); //通过数组名.length 就可以自动求出长度问题

        //遍历数组
      /*  for(int x: array) {
            System.out.println(x);
        }*/
        //只是单独打印数组 可以用到这个方法
        String str = Arrays.toString(array);
        System.out.println(str);

        System.out.println("=======");

        //数组排序:从小到大排序
        Arrays.sort(array);
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }

    //求阶乘和
    public static int facNum(int a) {
        int num = 0;
        for (int i = 1; i <= a; i++) {
            int ret = 1;
            for (int j = 1; j <= i; j++) {
                ret *= j;
            }
            num += ret;
        }
        return num;
    }
    public static void main2(String[] args) {
        int n = 4;
        int tmp = facNum(n);
        System.out.println(tmp);
    }

    //注意并没有成功交换两个数字，以后学习了类和对象可以解决
    public static void swap(int a , int b) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    public static void main1(String[] args) {
        int a = 10;
        int b = 20;
        swap(a,b);
        System.out.println(a);
        System.out.println(b);
    }
}
